'use strict';
module.exports = app => {
    const { STRING, INTEGER } = app.Sequelize;
    const User = app.model.define(
        'user',
        {
            id: {type: INTEGER, primaryKey: true, autoIncrement: true},
            role_id: INTEGER,
            shop_id: INTEGER,
            nickname: STRING(30),
            avatar_url: STRING(255),
            phone: STRING(30),
            description: STRING(255),
            username: STRING(30),
            password: STRING(255),
        },
        {
            tableName: 'user',
            timestamps: true, // 启用时间戳(createdAt, updatedAt)
            updatedAt: 'updated_time', // 不想要 updatedAt
            createdAt: 'create_time', // 想要  createdAt 但是希望名称叫做 created_at
        }
    );
    User.associate = function() {
        app.model.User.belongsTo(app.model.Role, {foreignKey: 'role_id', targetKey: 'id'});
        app.model.User.belongsTo(app.model.Shop, {foreignKey: 'shop_id', targetKey: 'id'});
    }
    return User
};
